package com.mxt.linkPerson.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mxt.common.vo.Result;
import com.mxt.linkPerson.entity.Person;
import com.mxt.linkPerson.mapper.PersonMapper;
import com.mxt.record.entity.Cord;
import com.mxt.record.mapper.CordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mxt
 * @since 2023-06-20
 */
@RestController
@CrossOrigin
@RequestMapping("/linkPerson")
public class PersonController {

    @Autowired
    private PersonMapper personMapper;
    @Autowired
    private CordMapper cordMapper;

    @PostMapping()
    public Result addPerson(@RequestBody Person person){
        personMapper.insert(person);
        return Result.success();
    }
    @GetMapping("/page")
    public Result selectPerson(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        Page<Person> page = new Page<>(pageNum,pageSize);
        Page<Person> personPage = personMapper.selectPage(page,null);
        List<Person> list = personPage.getRecords();
        return Result.success(list);
    }
    @GetMapping("/search")
    public Result searchPerson(String handlerName){

        QueryWrapper<Person> wrapper = new QueryWrapper<>();
        wrapper.like("handler_name",handlerName);
        List<Person> list = personMapper.selectList(wrapper);
        return Result.success(list);
    }

    @PostMapping("/delay")
    public Result delayRecord(@RequestBody Person person){
        Integer idrecord = person.getIdrecord();
        Cord cord = cordMapper.selectById(idrecord);
        cord.setStatue("已处理");
        cordMapper.updateById(cord);
        return Result.success();
    }

}
